import requests
import json

# 使用Cookie
cookies = {
    '_T_WM': '36461060359',
    'WEIBOCN_FROM': '1110006030',
    'SCF': 'AqEId5GjqmGHOqOirAAa0JnK3_-nh4hBJugbTGn-p4AFbn0nIoNQT9P5nNdkFWw2W7txLAYEhGSdnw1_CyrMOio.',
    'SUB': '_2A25F92KEDeRhGe5N71US9SrPwz6IHXVmjfpMrDV6PUJbktANLWmhkW1NdRhtpRCXpQmHezcxDS5qcDhqyhKj-vBB',
    'SUBP': '0033WrSXqPxfM725Ws9jqgMF55529P9D9W5jkHasEnXRCOCCXuX0714W5NHD95QRe0BNe0-Xe0nEWs4Dqcj.i--Ri-8siKL2i--ciKLhi-8si--Xi-i2i-27i--fiK.7iKn0',
    'SSOLoginState': '1760760532',
    'ALF': '1763352532',
    'MLOGIN': '1',
    'XSRF-TOKEN': '7fceb1',
    'mweibo_short_token': '2006f07847'
}

headers = {
    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
    'Referer': 'https://m.weibo.cn/',
    'Accept': 'application/json, text/plain, */*',
    'X-Requested-With': 'XMLHttpRequest'
}

url = 'https://m.weibo.cn/detail/5223067732415795'

try:
    response = requests.get(url, cookies=cookies, headers=headers, timeout=10)
    
    print(f"状态码: {response.status_code}")
    print(f"响应头: {dict(response.headers)}")
    
    if response.status_code == 200:
        print("访问成功！")
        
        # 尝试解析JSON数据（微博详情页通常是JSON格式）
        try:
            data = response.json()
            print("JSON数据解析成功")
            print(f"微博ID: {data.get('data', {}).get('id', '未知')}")
            print(f"微博内容: {data.get('data', {}).get('text', '未知')[:100]}...")
        except json.JSONDecodeError:
            print("66666666666")
            print(response.text)
            print("66666666666")
            # 如果是HTML页面
            if '<title>' in response.text:
                title_start = response.text.find('<title>') + 7
                title_end = response.text.find('</title>')
                title = response.text[title_start:title_end]
                print(f"页面标题: {title}")
            else:
                print("响应内容前200字符:", response.text[:200])
                
    elif response.status_code == 403:
        print("访问被拒绝，可能Cookie已过期或IP被封")
    else:
        print(f"访问失败，状态码: {response.status_code}")
        
except Exception as e:
    print(f"请求出错: {e}")
